<?php
include "conn.php";
$data = $_POST;

function addBlog(): bool
{
    global $mysql;
    global $data;
//    echo 233;
    $title = mysqli_real_escape_string($mysql, $data['title']);
    $content = mysqli_real_escape_string($mysql, $data['content']);
    $author = mysqli_real_escape_string($mysql, $data['author']);
    $res = mysqli_query($mysql, "INSERT INTO tb_blog(title, content, publish, author) VALUES ('$title', '$content', now(), '$author');");
    if ($res !== true) {
        echo mysqli_error($mysql);
        return false;
    }
    return true;
}

?>

<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>提交结果</title>
</head>
<body>
<?php
if (addBlog())
    echo "<a href='index.php'>提交成功！点我返回首页</a>";
else echo "失败！返回重新提交！";
?>
</body>
</html>
